<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>随机点名</title>
</head>
<body>
  <script>
    function getRandom(N,M){
      return Math.floor(Math.random()* ( M - N + 1)) +N
    }
    let random = getRandom(1,10)
    console.log(random)
    let flag = true
    for (let i = 1;i<=3;i++){
      let num = +prompt('请输入一个1~ 10您猜的数字：')

      if (num>random){
        alert(`您猜大了，继续猜还剩下${3-i}次机会`)
      }else if(num< random){
        alert(`您猜小了，继续猜还剩下${3-i}次机会`)
      }else{
        flag = false
        alert('猜对啦！，您真厉害')
        break
      }
    }
    if (flag){
      alert('3次机会已经用完了')
    }
      
    </script>
</body>
</html>